home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / GD / gd1_2_tar.z / gd1_2_tar / gd1.2 / giftogd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-08  |  855 b   |  39 lines

  1. #include <stdio.h>
  2. #include "gd.h"
  3.  
  4. /* A short program which converts a .gif file into a .gd file, for
  5.     your convenience in creating images on the fly from a
  6.     basis image that must be loaded quickly. The .gd format
  7.     is not intended to be a general-purpose format. */
  8.  
  9. int main(int argc, char **argv)
  10. {
  11.     gdImagePtr im;
  12.     FILE *in, *out;
  13.     if (argc != 3) {
  14.         fprintf(stderr, "Usage: giftogd filename.gif filename.gd\n");
  15.         exit(1);
  16.     }
  17.     in = fopen(argv[1], "rb");
  18.     if (!in) {
  19.         fprintf(stderr, "Input file does not exist!\n");
  20.         exit(1);
  21.     }
  22.     im = gdImageCreateFromGif(in);
  23.     fclose(in);
  24.     if (!im) {
  25.         fprintf(stderr, "Input is not in GIF format!\n");
  26.         exit(1);
  27.     }
  28.     out = fopen(argv[2], "wb");
  29.     if (!out) {
  30.         fprintf(stderr, "Output file cannot be written to!\n");
  31.         gdImageDestroy(im);
  32.         exit(1);    
  33.     }
  34.     gdImageGd(im, out);
  35.     fclose(out);
  36.     gdImageDestroy(im);
  37. }
  38.  
  39.